<!-- 搜索表单 -->
<template>
  <el-form
    label-width="77px"
    class="ele-form-search"
    @keyup.enter.native="search"
    @submit.native.prevent
  >
    <el-row :gutter="15">
      <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">
        <el-form-item label="代理账号:">
          <el-input clearable v-model="where.oemCode" placeholder="请输入" />
        </el-form-item>
      </el-col>
      <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">
        <el-form-item label="代理类型:">
          <el-select
            clearable
            v-model="where.agencyId"
            placeholder="请选择"
            class="ele-fluid"
          >
            <el-option v-for="(i,j) in typeList" :key="j" :label="i.agencyName" :value="i.id" />
          </el-select>
        </el-form-item>
      </el-col>
      <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">
        <el-form-item label="联系人:">
          <el-input clearable v-model="where.linkman" placeholder="联系人" />
        </el-form-item>
      </el-col>
      <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">
        <el-form-item label="联系电话:">
          <el-input clearable v-model="where.phone" placeholder="联系电话" />
        </el-form-item>
      </el-col>
      <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">
        <el-form-item label="创建时间:">
          <el-date-picker
            v-model="dateRange"
            type="daterange"
            unlink-panels
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd HH:mm:ss"
            class="ele-fluid"
          />
        </el-form-item>
      </el-col>
      <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">
        <el-form-item label="是否冻结:">
          <el-select
            clearable
            v-model="where.status"
            placeholder="请选择"
            class="ele-fluid"
          >
            <el-option label="启用" :value="1" />
            <el-option label="冻结" :value="2" />
          </el-select>
        </el-form-item>
      </el-col>
      <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">
        <div class="ele-form-actions">
          <el-button
            type="primary"
            icon="el-icon-search"
            class="ele-btn-icon"
            @click="search"
          >
            查询
          </el-button>
          <el-button @click="reset">重置</el-button>
        </div>
      </el-col>
    </el-row>
  </el-form>
</template>

<script>
  export default {
    data() {
      // 默认表单数据
      const defaultWhere = {
        oemType: 1,
        username: '',
        nickname: '',
        deleted: '0',
        sex: undefined
      };
      return {
        dateRange:[],
        // 表单数据
        where: { ...defaultWhere }
      };
    },
    props:{
      typeList:Array
    },
    computed: {
      // 是否开启响应式布局
      styleResponsive() {
        return this.$store.state.theme.styleResponsive;
      }
    },
    methods: {
      /* 搜索 */
      search() {
        if(!this.dateRange){
          delete this.where.startTime
          delete this.where.endTime
        }
        if(!this.where.oemCode){
          delete this.where.oemCode
        }
        if(!this.where.linkman){
          delete this.where.linkman
        }
        if(!this.where.phone){
          delete this.where.phone
        }
        if(this.dateRange) {
          this.where.startTime = this.dateRange[0]
          this.where.endTime = this.dateRange[1]
        }
        // 手机号验证
        if(this.where.phone && this.$sun.checkModbile(this.where.phone)==false){
          this.$message.error('手机号码格式不正确！');
          return
        }
        this.$emit('search', this.where);
      },
      /*  重置 */
      reset() {
        this.where = { ...this.defaultWhere };
        this.dateRange=[]
        delete this.where.startTime
        delete this.where.endTime
        this.$emit('search', this.where);
      }
    }
  };
</script>
